package org.easy.db.generator.util;

/**
 * @Description:
 * @Author: wxl
 * @CreateTime: 2023/1/28 9:44
 */
public class SysUtil {

    public static boolean isLinux () {
        return OsInfo.isLinux();
    }


    enum EPlatForm{
        /**
         *
         */
        Any("any"),
        Linux("Linux"),
        Mac_OS("Mac OS"),
        Mac_OS_X("Mac OS X"),
        Windows("Windows"),
        OS2("OS/2"),
        Solaris("Solaris"),
        SunOS("SunOS"),
        MPEiX("MPE/iX"),
        HP_UX("HP-UX"),
        AIX("AIX"),
        OS390("OS/390"),
        FreeBSD("FreeBSD"),
        Irix("Irix"),
        Digital_Unix("Digital Unix"),
        NetWare_411("NetWare"),
        OSF1("OSF1"),
        OpenVMS("OpenVMS"),
        Others("Others");

        EPlatForm(String desc){
            this.description = desc;
        }

        @Override
        public String toString(){
            return description;
        }

        private final String description;
    }

    public static class OsInfo {
        
        private static final String OS = System.getProperty("os.name").toLowerCase();

        private static final OsInfo instance = new OsInfo();

        private EPlatForm platform;

        private OsInfo(){}

        public static boolean isLinux(){
            return OS.contains("linux");
        }

        public static boolean isMacOs(){
            return OS.contains("mac") &&OS.indexOf("os")>0&& !OS.contains("x");
        }

        public static boolean isMacOsx(){
            return OS.contains("mac") &&OS.indexOf("os")>0&&OS.indexOf("x")>0;
        }

        public static boolean isWindows(){
            return OS.contains("windows");
        }

        public static boolean isOS2(){
            return OS.contains("os/2");
        }

        public static boolean isSolaris(){
            return OS.contains("solaris");
        }

        public static boolean isSunOs(){
            return OS.contains("sunos");
        }

        public static boolean isMPEiX(){
            return OS.contains("mpe/ix");
        }

        public static boolean isHPux(){
            return OS.contains("hp-ux");
        }

        public static boolean isAix(){
            return OS.contains("aix");
        }

        public static boolean isOs390(){
            return OS.contains("os/390");
        }

        public static boolean isFreeBsd(){
            return OS.contains("freebsd");
        }

        public static boolean isIrix(){
            return OS.contains("irix");
        }

        public static boolean isDigitalUnix(){
            return OS.contains("digital") &&OS.indexOf("unix")>0;
        }

        public static boolean isNetWare(){
            return OS.contains("netware");
        }

        public static boolean isOsf1(){
            return OS.contains("osf1");
        }

        public static boolean isOpenVms(){
            return OS.contains("openvms");
        }

        public static EPlatForm getOsName(){
            if(isAix()){
                instance.platform = EPlatForm.AIX;
            }else if (isDigitalUnix()) {
                instance.platform = EPlatForm.Digital_Unix;
            }else if (isFreeBsd()) {
                instance.platform = EPlatForm.FreeBSD;
            }else if (isHPux()) {
                instance.platform = EPlatForm.HP_UX;
            }else if (isIrix()) {
                instance.platform = EPlatForm.Irix;
            }else if (isLinux()) {
                instance.platform = EPlatForm.Linux;
            }else if (isMacOs()) {
                instance.platform = EPlatForm.Mac_OS;
            }else if (isMacOsx()) {
                instance.platform = EPlatForm.Mac_OS_X;
            }else if (isMPEiX()) {
                instance.platform = EPlatForm.MPEiX;
            }else if (isNetWare()) {
                instance.platform = EPlatForm.NetWare_411;
            }else if (isOpenVms()) {
                instance.platform = EPlatForm.OpenVMS;
            }else if (isOS2()) {
                instance.platform = EPlatForm.OS2;
            }else if (isOs390()) {
                instance.platform = EPlatForm.OS390;
            }else if (isOsf1()) {
                instance.platform = EPlatForm.OSF1;
            }else if (isSolaris()) {
                instance.platform = EPlatForm.Solaris;
            }else if (isSunOs()) {
                instance.platform = EPlatForm.SunOS;
            }else if (isWindows()) {
                instance.platform = EPlatForm.Windows;
            }else{
                instance.platform = EPlatForm.Others;
            }
            return instance.platform;
        }
        
    }

}
